import { reactive } from "vue"
export const infoList = (listApi) => {
  const tableInfo = reactive({
    page: 1,
    total: 10,
    pageSize: 10,
    tableData: [],
    searchInfo: {}
  })

  const handleSizeChange = (val) => {
    tableInfo.pageSize = val;
    getTableData();
  }

  const handleCurrentChange = (val) => {
    tableInfo.page = val;
    getTableData();
  }

  const getTableData = async() => {
    const res = await listApi({ page: tableInfo.page, pageSize: tableInfo.pageSize, ...tableInfo.searchInfo });
    tableInfo.tableData = res.data.list;
    tableInfo.total = res.data.total;
    tableInfo.page = res.data.page;
    tableInfo.pageSize = res.data.pageSize;
  }
  
  return {
    tableInfo,
    handleSizeChange,
    handleCurrentChange,
    getTableData,
  }
}